package net.googlecode.kharchenko.services.impl;

import net.googlecode.kharchenko.dao.GroupDAO;
import net.googlecode.kharchenko.dao.PersonDAO;
import net.googlecode.kharchenko.domains.Group;
import net.googlecode.kharchenko.domains.Person;
import net.googlecode.kharchenko.services.PersonService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Person Service Implementation. All methods are transactional.
 *
 * @author Kharchenko Yaroslav
 */
@Service
public class PersonServiceImpl implements PersonService {

    @Autowired
    private PersonDAO personDAO;

    @Autowired
    private GroupDAO groupDAO;


    @Transactional
    public Person getPerson(String email) {
        return personDAO.getPerson(email);
    }


    @Transactional
    public List getGroupMates(Person prs) {
        return personDAO.getGroupMates(prs);

    }

    @Transactional
    public List getTop5() {
        return personDAO.getTop5();
    }


    @Transactional
    public List getAllGroups() {
        return groupDAO.getAllGroups();

    }


    @Transactional
    public void savePerson(Person prs) {

        personDAO.savePerson(prs);
    }


    @Transactional
    public Group getGroup(Long id) {
        return groupDAO.getGroup(id);
    }


    @Transactional
    public Person getPersonById(Long id) {

        return personDAO.getPersonById(id);
    }


    @Transactional
    public void giveVote(Long id, Person prs) {

        personDAO.giveVote(id, prs);
    }


    @Transactional
    public boolean isVoteGiven(Long id, Person prs) {
        return personDAO.isVoteGiven(id, prs);

    }


    @Transactional
    public void takeAwayVote(Long id, Person prs) {
        personDAO.takeAwayVote(id, prs);
    }


    @Transactional
    public void updatePersonInfo(String email, Person prs) {
        personDAO.updatePersonInfo(email, prs);
    }

    @Transactional
    public void changePassword(String email, String newPass) {
        personDAO.changePassword(email, newPass);
    }
}
